//输入	1 6
//2 4 1 5 3 3
//输出	1 6
//0 1 1 2 1 1
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n; // m行, n列
let initArr = [];
rl.on("line", (line)=>{
    if(m === undefined) {
        [m, n] = line.trim().split(" ").map(Number)
    } else {
        initArr = line.trim().split(" ").map(Number)
        getResult(m, n, initArr);
        // clear
        m = n = undefined
        initArr.length = 0;
    }
})

/**
 *
 * @param m 行数
 * @param n 列数
 * @param initArr {[number]} 一维源数组
 * @return {void}
 */
function getResult(m, n, initArr) {
    const resultArr = new Array(m).fill(null).map(_ => new Array(n).fill(0))

    // 高度二维数组
    const heightArr = []
    for (let i = 0; i < m; i++) {
        heightArr.push([...initArr.slice(i*n, i*n + n)])
    }

    // 处理行
    for (let i = 0; i < m && n > 1; i++) {
        let arr = heightArr[i]
        let stack = [arr[0]]

        for (let j = 1; j < arr.length; j++) {
            let count = 0;
            while(stack.length){
                if(arr[j] >= stack.at(-1)) {
                    stack.pop();
                    count++;
                }  else if (arr[j] < stack.at(-1)){
                    count++;
                    break;
                }
            }
            stack.push(arr[j])
            resultArr[i][j]+= count
        }
    }

    // 处理列
    for (let i = 0; i < n && m > 1; i++) {
        let arr = []
        for (let j = 0; j < m; j++) {
            arr.push(heightArr[j][i])
        }

        let stack = [arr[0]]

        for (let j = 1; j < arr.length; j++) {
            let count = 0;
            while(stack.length){
                if(arr[j] >= stack.at(-1)) {
                    stack.pop();
                    count++;
                }  else if (arr[j] < stack.at(-1)){
                    count++;
                    break;
                }
            }
            stack.push(arr[j])
            resultArr[j][i]+= count
        }
        arr.length = 0; // 清空
    }
    console.log(`${m} ${n}`)
    let result = []
    for (let i = 0; i < m; i++) {
        result.push(resultArr[i].join(" "))
    }
    console.log(result.join(" "))
}